<template>
    <span @click="copyFunc">
        <img :width="size.width" :height="size.height" src="@/assets/images/copy.png" alt="copy">
    </span>
</template>
<script setup lang="ts">
import { showToast } from 'vant';

const props = defineProps({
  text: {
    type: String,
    default: ''
  },
  size:{
    type:Object,
    default: () => ({
        width: '20px',
        height: '20px'
    })
  }
})

const copyFunc = ()=>{
    navigator.clipboard.writeText(props.text).then(()=>{
        showToast({
            type: 'success',
            message: '复制成功',
            duration: 1000
        })
    }).catch(()=>{
        showToast({
            type: 'fail',
            message: '复制失败',
            duration: 1000
        })
    })
}
</script>